﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SecsEquip;
using System.Threading;
using SecsEquip300;
using EquipViewAppNet;
using System.Diagnostics;

namespace EquipSecs300
{
    class CSecsEquipInstance
    {
        static public CSecsEquip300 m_pSecs = null;

        CSecsEquipInstance(){}

        public static CSecsEquip300 GetSecsInstance(bool isCreateSelf)
        {
            try
            {
                if (m_pSecs == null)
                {
                    if (!isCreateSelf)
                    {
                        ProcessKill();
                    }
                    m_pSecs = new CSecsEquip300();
                }
                return m_pSecs;
            }
            catch (System.Exception ex)
            {
                m_pSecs = null;
            }
            return m_pSecs;
        }

        private static void ProcessKill()
        {
            string processName = "JNG_Server";
            foreach (var process in Process.GetProcessesByName(processName))
            {
                try
                {
                    process.Kill();
                    process.WaitForExit();
                }
                catch (Exception ex)
                {

                }
            }
        }

    }


}
